package com.wxtt.android;

import android.app.Activity;

import com.fast.dev.frame.AbstractApplication;
import com.fast.dev.frame.glide.GlideLoader;
import com.fast.dev.frame.http.HttpConfig;
import com.fast.dev.frame.utils.Constant;
import com.fast.dev.frame.utils.FileUtils;
import com.fast.dev.frame.utils.LogUtils;
import com.wxtt.android.config.ConstantConfig;
import com.wxtt.android.crash.MyCrashHandler;
import com.youku.player.YoukuPlayerBaseConfiguration;

import java.io.File;

import cn.bmob.push.BmobPush;
import cn.bmob.v3.Bmob;
import cn.bmob.v3.BmobInstallation;

/**
 * 说明：BaseApplication
 * <p/>
 * 作者：fanly
 * <p/>
 * 时间：2015/12/26 10:50
 * <p/>
 * 版本：verson 1.0
 */
public class BaseApplication extends AbstractApplication {

    private static YoukuPlayerBaseConfiguration youkuConfig;

    @Override
    public void onCreate() {
        super.onCreate();
        init();
    }

    private void init(){
        FileUtils.deleteAllFile(new File(Constant.FilePath.CRASHHANDLER_CACHEPATH));
        MyCrashHandler.getInstance().create(this, Constant.FilePath.CRASHHANDLER_CACHEPATH);

        //初始化HttpConfig
        HttpConfig.Builder httpBuilder = new HttpConfig.Builder(this);
        httpBuilder.setDebug(true);
        httpBuilder.setTrustAll(true);
        httpBuilder.build().init();
        //开启打印日志
        LogUtils.init(true);
        //设置全局占位图和错误图
        GlideLoader.setGlobleHolder(R.mipmap.place_holder, R.mipmap.place_holder);

        initBomb();
        initYouku();
    }

    /**
     * 说明：初始化Bmob服务
     */
    private void initBomb(){
        //初始化BMOB
        Bmob.initialize(this, ConstantConfig.BMOB_APPID);
        //初始化消息推送
        BmobInstallation.getCurrentInstallation(this).save();
        BmobPush.startWork(this, ConstantConfig.BMOB_APPID);
    }

    /**
     * 说明：初始化优酷信息
     */
    private void initYouku(){
        youkuConfig = new YoukuPlayerBaseConfiguration(this) {
            @Override
            public Class<? extends Activity> getCachingActivityClass() {
                return null;
            }

            @Override
            public Class<? extends Activity> getCachedActivityClass() {
                return null;
            }

            @Override
            public String configDownloadPath() {
                return Constant.FilePath.YOUKU_VIDEO;
            }
        };
    }

}
